//
//  TSCVCCreateShop.m
//  Tsc_IOS
//
//  Created by Rio on 15-6-3.
//  Copyright (c) 2015年 idream. All rights reserved.
//

#import "TSCVCCreateShopGatherInfo.h"
#import "TSCSDK.h"
#import "TSCVCCreateShopSearchMall.h"


@interface TSCVCCreateShopGatherInfo () {
    // 输入参数
    NSInteger _iCityId;
    
    // 从其他vc获得的参数：
    NSInteger _rMallId; // r == return
    
    // 图片上传后的URL，图片上传成功后保存进来
    NSString * _rImgUrlLogo;
    NSString * _rImgUrlFrontPhoto;
}

@property (weak, nonatomic) IBOutlet UILabel *lbCreateShopInfo;
@property (weak, nonatomic) IBOutlet UITextField *tfShopName;
@property (weak, nonatomic) IBOutlet UITextField *tfSelectMall;
@property (weak, nonatomic) IBOutlet TSCMyGCSelectorDialog *gcsdGC;
@property (weak, nonatomic) IBOutlet TSCMyUploadPicDialog *updLogo;
@property (weak, nonatomic) IBOutlet UIImageView *ivLogo;
@property (weak, nonatomic) IBOutlet TSCMyUploadPicDialog *updFrontPhoto;
@property (weak, nonatomic) IBOutlet UIImageView *ivFrontPhoto;
@property (weak, nonatomic) IBOutlet UITextField *tfPhone;
@property (weak, nonatomic) IBOutlet UIButton *btnCreate;

@end

@implementation TSCVCCreateShopGatherInfo

#pragma mark 校验并获取输入
- (void) getVCInput:(NSNotificationCenter *)notification {
    [super getVCInput:notification];
    
    _iCityId = [[_inputDic objectForKey:AEKI_CITY_ID] intValue];
    
    NSAssert(_iCityId != 0, @"%s: 输入参数必须包括：%@！", __FUNCTION__, AEKI_CITY_ID);
}

+ (id) vcCreateShopWithStoryboard {
    UIStoryboard * sb = [UIStoryboard storyboardWithName:UI_STORYBOARD_NAME_MAIN bundle:[NSBundle mainBundle]];
    return [sb instantiateViewControllerWithIdentifier:UI_VC_NAME_CREATE_SHOP_GATHER_INFO];
}

//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        // Custom initialization
//    }
//    return self;
//}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 设置自定义导航栏
    _nbc = [[TSCMyNaviBarCreator alloc]initAndCreateWithViewController:self hasGoBackButton:YES goBackVC:nil hasAppLogo:YES titleResourceKey:@"title_create_shop" iconResourceNameArray:nil iconClickedListenerArray:nil];
    
    // ===== 初始化UI
    
    // 初始化文字说明
    _lbCreateShopInfo.text = NSLocalizedString(@"content_create_shop", nil);
    
    // 初始化店铺名称
    _tfShopName.placeholder = NSLocalizedString(@"hint_shop_name_eg", nil);
    
    // 初始化选择商场
    _tfSelectMall.placeholder = NSLocalizedString(@"hint_select_mall", nil);
    [TSCMyUIUtil addDownTriangleIconToView:_tfSelectMall direction:IconDirectionRight];
    
    // 初始化选择商品分类
    _gcsdGC.placeholder = NSLocalizedString(@"hint_select_goods_class", nil);
    [_gcsdGC initPickerDisplay_1];
    
    // 初始化上传logo
    _updLogo.placeholder = NSLocalizedString(@"hint_upload_logo", nil);
    [self createUpdLogo];
    
    // 初始化上传门面相片
    _updFrontPhoto.placeholder = NSLocalizedString(@"hint_upload_front_photo", nil);
    [self createUpdFrontPhoto];
    
    // 初始化电话
    _tfPhone.placeholder = NSLocalizedString(@"hint_input_phone_optional", nil);
    
    // 初始化创建按钮
    [_btnCreate setTitle:NSLocalizedString(@"btn_create", nil) forState:UIControlStateNormal];
    
    
    // 注册事件——选择商场
    
    // 注册事件——上传Logo
    // 注册事件——查看已上传的Logo
    _ivLogo.userInteractionEnabled = YES;
    UITapGestureRecognizer * tgrIvLogoClicked = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ivLogoClicked)];
    [_ivLogo addGestureRecognizer:tgrIvLogoClicked];
    
    // 注册事件——上传门面相片
    // 注册事件——查看已上传的门面相片
    _ivFrontPhoto.userInteractionEnabled = YES;
    UITapGestureRecognizer * tgrIvFrontPhotoClicked = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(ivFrontPhotoClicked)];
    [_ivFrontPhoto addGestureRecognizer:tgrIvFrontPhotoClicked];
    
    // 注册事件——创建（店铺）
}

- (void) viewWillAppear:(BOOL)animated {
    // 如果从搜索店铺vc返回，则输入中应该有mallId、mallName
    _rMallId = [[_inputDic objectForKey:AEKI_MALL_ID] integerValue];
    NSString * selectedMallName = [_inputDic objectForKey:AEKI_MALL_NAME];
    
    if (selectedMallName) {
        _tfSelectMall.text = selectedMallName;
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
 {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

#pragma mark 私有方法

/* private */ - (void) createUpdLogo {
    // 创建customView
    // 1 上部
    TSCLinearLayout * llTopPanel = [[TSCLinearLayout alloc]init];
    llTopPanel.orientation = LINEAR_LAYOUT_ORIENTATION_HORIZONTAL; // 水平
    llTopPanel.paddingC2F = 10.0f;
    llTopPanel.paddingC2C = 10.0f;
    
    UIImageView * ivHelp = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_help_96x96.png"]];
    ivHelp.frame = CGRectMake(0, 0, 30, 30); // 仅设置宽高
    [TSCMyUIUtil addVacancyWithW:30 H:60 forView:ivHelp inView:llTopPanel];
    
    UITextView * tvInfo = [[UITextView alloc]init]; // 注：UITextView，只能使文字顶部，无法使文字垂直居中，所以改用UITextField
    //    UITextField * tvInfo = [[UITextField alloc]init]; // 注：因为UITextField只能单行，所以还得使用UITextView
    //    tvInfo.enabled = false;
    tvInfo.font = [TSCMyUIUtil getSystemDefaultFont];
    tvInfo.text = NSLocalizedString(@"content_logo_intro", nil);
    [llTopPanel addSubview:tvInfo];
    
    // 2 中部
    UIImageView * ivLogo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_sample_logo_320x320.png"]];
    UIView * ivLogoPanel = [[UIView alloc]init];
    [ivLogoPanel addSubview:ivLogo];
    
    // 约束
    // iv
    ivLogo.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:ivLogo attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:ivLogoPanel attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[ivLogo(200)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ivLogo)]];
    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[ivLogo(200)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ivLogo)]];
    
    // 3 整体
    TSCLinearLayout * llCustomView = [[TSCLinearLayout alloc]init];
    [llCustomView addSubview:llTopPanel];
    [llCustomView addSubview:ivLogoPanel];
    
    // 创建图片选择器
    _updLogo.title = NSLocalizedString(@"title_upload_logo", nil);
    _updLogo.bodyView = llCustomView;
    _updLogo.maxPhotoPickNum = 1; // 最多拍照/选择一张
    
    // 注册事件——当拍照完毕，或者从相册选择完毕（支持多选）后
    _updLogo.myImagePickerControllerDidCancel = ^(UINavigationController * picker) {
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
    };
    _updLogo.myImagePickerControllerDidFinishPickingMediaWithInfo = ^(UINavigationController * picker, NSArray * infoArr) {
        
        // 后台处理
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            // 注：只有一张图片
            for (NSDictionary * info in infoArr) {
                NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
                UIImage *originalImage, *editedImage, *imageToSave;
                
                if (
                    // 系统自带：当返回的相片为此类型时，表示是通过系统自带的拍照功能获得的相片（一张）
                    (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo)
                    ||
                    // ELC：当返回的相片为此类型时，表示是通过ELC从相册中选择的相片（一张，或者多张）
                    [mediaType isEqualToString:ALAssetTypePhoto]
                    ) {
                    editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
                    originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
                    
                    if (editedImage) {
                        imageToSave = editedImage;
                    } else {
                        imageToSave = originalImage;
                    }
                    
                    // 回到主线程
                    dispatch_async(dispatch_get_main_queue(), ^{
                        // 进入相片编辑vc
                        TSCVCPhotoEditor * vcPhotoEditor = [TSCVCPhotoEditor vcPhotoEditorWithStoryboard];
                        vcPhotoEditor.callbackAfterImageEdited = ^(TSCVCPhotoEditor * vc, UIImage * imageAfterEditied) {
                            // 将裁减后的UIImage保存在iv上
                            _ivLogo.image = imageAfterEditied;
                            
                            // 退出相片编辑vc
                            [[self navigationController] popViewControllerAnimated:vc];
                        };
                        [[self navigationController] pushViewController:vcPhotoEditor animated:YES];
                        
                        // VC间传递参数
                        NSDictionary * inputDic = [NSDictionary dictionaryWithObject:imageToSave forKey:AEKI_UIIMAGE];
                        [[NSNotificationCenter defaultCenter] addObserver:vcPhotoEditor selector:@selector(SELECTOR_GET_VC_INPUT) name:UI_VC_NAME_PHOTO_EDITOR object:nil];
                        [[NSNotificationCenter defaultCenter] postNotificationName:UI_VC_NAME_PHOTO_EDITOR object:inputDic];
                        
                        return;
                    });
                }
            }
        }); // end dispatch
        
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
        [_updLogo dismiss];
        
    }; // end delegate注册
}

/* private */ - (void) createUpdFrontPhoto {
    // 创建customView
    // 1 上部
    TSCLinearLayout * llTopPanel = [[TSCLinearLayout alloc]init];
    llTopPanel.orientation = LINEAR_LAYOUT_ORIENTATION_HORIZONTAL; // 水平
    llTopPanel.paddingC2F = 10.0f;
    llTopPanel.paddingC2C = 10.0f;
    
    UIImageView * ivHelp = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_help_96x96.png"]];
    ivHelp.frame = CGRectMake(0, 0, 30, 30); // 仅设置宽高
    [TSCMyUIUtil addVacancyWithW:30 H:60 forView:ivHelp inView:llTopPanel];
    
    UITextView * tvInfo = [[UITextView alloc]init]; // 注：UITextView，只能使文字顶部，无法使文字垂直居中，所以改用UITextField
    //    UITextField * tvInfo = [[UITextField alloc]init]; // 注：因为UITextField只能单行，所以还得使用UITextView
    //    tvInfo.enabled = false;
    tvInfo.frame = CGRectMake(0, 0, 0, 60); // 仅设置高度
    tvInfo.font = [TSCMyUIUtil getSystemDefaultFont];
    tvInfo.text = NSLocalizedString(@"content_front_photo_intro", nil);
    [llTopPanel addSubview:tvInfo];
    
    // 2 中部
    UIImageView * ivLogo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ic_sample_front_photo_320x320.jpg"]];
    UIView * ivLogoPanel = [[UIView alloc]init];
    [ivLogoPanel addSubview:ivLogo];
    
    // 约束
    // iv
    ivLogo.translatesAutoresizingMaskIntoConstraints = NO;
    [NSLayoutConstraint constraintWithItem:ivLogo attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:ivLogoPanel attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f].active = YES;
    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[ivLogo(200)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ivLogo)]];
    [NSLayoutConstraint activateConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[ivLogo(200)]-10-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(ivLogo)]];
    
    // 3 整体
    TSCLinearLayout * llCustomView = [[TSCLinearLayout alloc]init];
    [llCustomView addSubview:llTopPanel];
    [llCustomView addSubview:ivLogoPanel];
    
    // 创建图片选择器
    _updFrontPhoto.title = NSLocalizedString(@"title_upload_front_photo", nil);
    _updFrontPhoto.bodyView = llCustomView;
    _updFrontPhoto.maxPhotoPickNum = 1; // 最多拍照/选择一张
    
    // 注册事件——当拍照完毕，或者从相册选择完毕（支持多选）后
    _updFrontPhoto.myImagePickerControllerDidCancel = ^(UINavigationController * picker) {
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
    };
    _updFrontPhoto.myImagePickerControllerDidFinishPickingMediaWithInfo = ^(UINavigationController * picker, NSArray * infoArr) {
        
        // 后台处理
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            
            // 注：只有一张图片
            for (NSDictionary * info in infoArr) {
                NSString *mediaType = [info objectForKey: UIImagePickerControllerMediaType];
                UIImage *originalImage, *editedImage, *imageToSave;
                
                if (
                    // 系统自带：当返回的相片为此类型时，表示是通过系统自带的拍照功能获得的相片（一张）
                    (CFStringCompare ((CFStringRef) mediaType, kUTTypeImage, 0) == kCFCompareEqualTo)
                    ||
                    // ELC：当返回的相片为此类型时，表示是通过ELC从相册中选择的相片（一张，或者多张）
                    [mediaType isEqualToString:ALAssetTypePhoto]
                    ) {
                    editedImage = (UIImage *) [info objectForKey:UIImagePickerControllerEditedImage];
                    originalImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];
                    
                    if (editedImage) {
                        imageToSave = editedImage;
                    } else {
                        imageToSave = originalImage;
                    }
                    
                    // 回到主线程
                    dispatch_async(dispatch_get_main_queue(), ^{
                        // 进入相片编辑vc
                        TSCVCPhotoEditor * vcPhotoEditor = [TSCVCPhotoEditor vcPhotoEditorWithStoryboard];
                        vcPhotoEditor.callbackAfterImageEdited = ^(TSCVCPhotoEditor * vc, UIImage * imageAfterEditied) {
                            // 将裁减后的UIImage保存在iv上
                            _ivFrontPhoto.image = imageAfterEditied;
                            
                            // 退出相片编辑vc
                            [[self navigationController] popViewControllerAnimated:vc];
                        };
                        [[self navigationController] pushViewController:vcPhotoEditor animated:YES];
                        
                        // VC间传递参数
                        NSDictionary * inputDic = [NSDictionary dictionaryWithObject:imageToSave forKey:AEKI_UIIMAGE];
                        [[NSNotificationCenter defaultCenter] addObserver:vcPhotoEditor selector:@selector(SELECTOR_GET_VC_INPUT) name:UI_VC_NAME_PHOTO_EDITOR object:nil];
                        [[NSNotificationCenter defaultCenter] postNotificationName:UI_VC_NAME_PHOTO_EDITOR object:inputDic];
                        
                        return;
                    });
                }
            }
        }); // end dispatch
        
        // 注：系统不会自动关闭，需要手动关闭
        [picker dismissViewControllerAnimated:YES completion:nil];
        [_updFrontPhoto dismiss];
        
    }; // end delegate注册
}

/* private */ - (void) resignAllFirstResponder {
    [_tfShopName resignFirstResponder];
    [_tfSelectMall resignFirstResponder];
    [_gcsdGC resignFirstResponder];
    [_updLogo resignFirstResponder]; // TODO 没用了
    [_updFrontPhoto resignFirstResponder]; // TODO 没用了
    [_tfPhone resignFirstResponder];
}

#pragma mark delegate

// return键收回键盘
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

// 点击空白区域收回键盘
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self resignAllFirstResponder];
}

// 注册事件——选择商场
- (IBAction)tfSelectMallTouchDown:(id)sender {
    TSCVCCreateShopSearchMall * vcCreateShopSearchMall = [TSCVCCreateShopSearchMall vcCreateShopSearchMallWithStoryBoard];
    [[self navigationController] pushViewController:vcCreateShopSearchMall animated:YES];
    
    // VC间传递参数
    NSDictionary * inputDic = [NSDictionary dictionaryWithObject:[NSNumber numberWithLong:_iCityId] forKey:AEKI_CITY_ID];
    [[NSNotificationCenter defaultCenter]addObserver:vcCreateShopSearchMall selector:@selector(SELECTOR_GET_VC_INPUT) name:UI_VC_NAME_CREATE_SHOP_SEARCH_MALL object:nil];
    [[NSNotificationCenter defaultCenter] postNotificationName:UI_VC_NAME_CREATE_SHOP_SEARCH_MALL object:inputDic];
}

// 注册事件——touch down时，关闭所有“可能”打开的键盘
- (IBAction)touchDownCloseKeyboard:(id)sender {
    // 注：所有注册到该事件上的UI元素，本身就会响应touch up inside事件，在此再次注册touch down事件，是为了关闭所有“可能”打开的键盘
    [self resignAllFirstResponder];
}

// 注册事件——查看已上传的Logo
- (void) ivLogoClicked {
    // 关闭所有“可能”打开的键盘
    [self resignAllFirstResponder];
    
    TSCMyPhotoDialog * photoDialog = [[TSCMyPhotoDialog alloc]initWithViewController:self image:_ivLogo.image];
    [photoDialog show];
}

// 注册事件——查看已上传的门面相片
- (void) ivFrontPhotoClicked {
    // 关闭所有“可能”打开的键盘
    [self resignAllFirstResponder];
    
    TSCMyPhotoDialog * photoDialog = [[TSCMyPhotoDialog alloc]initWithViewController:self image:_ivFrontPhoto.image];
    [photoDialog show];
}

// 注册事件——创建（店铺）
- (IBAction)btnCreateShopClicked:(id)sender {
    // 收回键盘
    [self resignAllFirstResponder];
    
    // 检查店铺名称
    if ([TSCMyCheckUtil checkWithString:_tfShopName.text regexType:RegexTypeShopName] == NO) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_format_shop_name"];
        return;
    }
    
    // 检查商场
    if ([TSCMyCheckUtil checkWithString:_tfSelectMall.text regexType:RegexTypeMallName] == NO) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_select_mall"];
        return;
    }
    
    // 检查商品分类
    if ([TSCMyCheckUtil checkWithString:[_gcsdGC getSelectedGCIds] regexType:RegexTypeGoodsClassIds] == NO) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_select_goods_class"];
        return;
    }
    
    // 检查Logo
    if (_ivLogo.image == nil) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_upload_logo"];
        return;
    }
    
    // 检查门面图片
    if (_ivFrontPhoto.image == nil) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_upload_front_photo"];
        return;
    }
    
    // 检查电话
    if ([TSCMyUtil isStringEmpty:_tfPhone.text] == NO && [TSCMyCheckUtil checkWithString:_tfPhone.text regexType:RegexTypePhone] == NO) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_format_phone"];
        return;
    }
    
    // 检查网络环境
    if ([TSCMyNetworkUtil checkNetwork] == false) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_network_unavailable"];
        return;
    }
    
    // 提示用户正在提交
    [self showDialogWithResourceKey:@"content_submitting" isProcessing:YES];
    
   	// 上传图片到图片服务器
    //    NSMutableDictionary * picKeyImageDic = [NSMutableDictionary dictionary];
    //    [picKeyImageDic setObject:_ivLogo.image forKey:@"logo"];
    //    [picKeyImageDic setObject:_ivFrontPhoto.image forKey:@"frontPhoto"];
    TSCMyUploadImageUtil * uploadImageUtil = [[TSCMyUploadImageUtil alloc]init];
    uploadImageUtil.picKeyImageDic = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects:_ivLogo.image, _ivFrontPhoto.image, nil] forKeys:[NSArray arrayWithObjects:@"logo", @"frontPhoto", nil]];
    uploadImageUtil.onSuccessOne = ^(NSString * key, NSString * imgUrl) {
        // 区分已经上传的图片是logo，还是门面图片，分别保存
        if ([key isEqualToString:@"logo"]) {
            _rImgUrlLogo = imgUrl;
        } else if ([key isEqualToString:@"frontPhoto"]) {
            _rImgUrlFrontPhoto = imgUrl;
        }
    };
    uploadImageUtil.onSuccessAll = ^(NSMutableDictionary * picKeyUrlDic) {
        [self createShop_PP1];
    };
    uploadImageUtil.onFailure = ^(NSError * error) {
        [TSCMyUIUtil popErrWithResourceKey:@"err_pic_server_unavailable"];
    };
    [uploadImageUtil startUpload_P1];
    
}

- (void) createShop_PP1 {
    
    // 拼装请求
    NSMutableDictionary * reqDic = [[NSMutableDictionary alloc] init];
    [reqDic setObject:[_ud objectForKey:UD_USER_ID] forKey:@"user_id"];
    [reqDic setObject:[_ud objectForKey:UD_LOGIN_KEY] forKey:@"login_key"];
    [reqDic setObject:[NSNumber numberWithInteger:_iCityId] forKey:@"city_id"];
    [reqDic setObject:[TSCMyUtil trim:_tfShopName.text] forKey:@"name"];
    [reqDic setObject:[NSNumber numberWithInteger:_rMallId] forKey:@"mall_id"];
    [reqDic setObject:[_gcsdGC getSelectedGCIds] forKey:@"goods_class_ids"];
    [reqDic setObject:_rImgUrlLogo forKey:@"logo_url"];
    [reqDic setObject:_rImgUrlFrontPhoto forKey:@"pic_url"];
    [reqDic setObject:[TSCMyUtil trim:_tfPhone.text] forKey:@"tel"];
    
    // 发送请求
    [TSCMyHttpUtil postWithUrl:URL_SHOP_CREATE dictionary:reqDic completionHandler:^(ServerRespType serverRespType, NSString * respString, NSDictionary *respDictionary, NSInteger code, NSString *msg, NSDictionary *contentDictionary) {
        // 服务器返回错误处理
        switch (serverRespType) {
            case ServerRespTypeSuccess:
                break;
            case ServerRespTypeErrNil:
            case ServerRespTypeErrJson: {
                [self dissmisDialog];
                [TSCMyUIUtil popErrWithResourceKey:@"err_web_server_unavailable"];
                return;
            }
            case ServerRespTypeErrCode:{
                [self dissmisDialog];
                [TSCMyUIUtil popErrWithString:msg];
                return;
            }
            default:
                [self dissmisDialog];
                [TSCMyUIUtil popErrWithResourceKey:@"err_system"];
                return;
        }
        
        // 继续后续逻辑...
        [self createShop_2:msg];
    }];
    
}

/* private */ - (void) createShop_2:(NSString *)serverRespMsg {
    TSCMyDialog * dialog = [[TSCMyDialog alloc]init];
    dialog.msgText = serverRespMsg;
    [_dialog replaceContentViewWithOtherDialog:dialog];
    
    // 稍后关闭界面
    [TSCMyUIUtil popVCLaterWithNVC:[self navigationController] animated:YES];
}

@end
